
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>SPIs &#8212; Freedom Metal v201905 documentation</title>
    <link rel="stylesheet" href="../_static/alabaster.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="index" title="Index" href="../genindex.html" />
    <link rel="search" title="Search" href="../search.html" />
    <link rel="next" title="Switches" href="switch.html" />
    <link rel="prev" title="Shutdown" href="shutdown.html" />
   
  <link rel="stylesheet" href="../_static/custom.css" type="text/css" />
  
  
  <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />

  </head><body>
  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          

          <div class="body" role="main">
            
  <div class="section" id="spis">
<h1>SPIs<a class="headerlink" href="#spis" title="Permalink to this headline">¶</a></h1>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Functions</p>
<dl class="function">
<dt id="_CPPv320metal_spi_get_devicei">
<span id="_CPPv220metal_spi_get_devicei"></span><span id="metal_spi_get_device__i"></span><span class="target" id="spi_8h_1a855e33042e8166cb66fc6b9f15c06d18"></span><em class="property">struct</em> <a class="reference internal" href="#_CPPv39metal_spi" title="metal_spi">metal_spi</a> *<code class="descname">metal_spi_get_device</code><span class="sig-paren">(</span>int <em>device_num</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv320metal_spi_get_devicei" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Get a handle for a SPI device. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>A handle to the SPI device, or NULL if the device does not exist </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">device_num</span></code>: The index of the desired SPI device </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv314metal_spi_initP9metal_spii">
<span id="_CPPv214metal_spi_initP9metal_spii"></span><span id="metal_spi_init__metal_spiP.i"></span><span class="target" id="spi_8h_1a8309f59b3cd7009ec36c94caec10567e"></span>void <code class="descname">metal_spi_init</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv39metal_spi" title="metal_spi">metal_spi</a> *<em>spi</em>, int <em>baud_rate</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv314metal_spi_initP9metal_spii" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Initialize a SPI device with a certain baud rate. </p>
<p><dl class="docutils">
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">spi</span></code>: The handle for the SPI device to initialize </li>
<li><code class="docutils literal notranslate"><span class="pre">baud_rate</span></code>: The baud rate to set the SPI device to </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv318metal_spi_transferP9metal_spiP16metal_spi_config6size_tPcPc">
<span id="_CPPv218metal_spi_transferP9metal_spiP16metal_spi_config6size_tPcPc"></span><span id="metal_spi_transfer__metal_spiP.metal_spi_configP.s.cP.cP"></span><span class="target" id="spi_8h_1a43416802fba9289bfcff5d42f61bcbd1"></span>int <code class="descname">metal_spi_transfer</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv39metal_spi" title="metal_spi">metal_spi</a> *<em>spi</em>, <em class="property">struct</em> <a class="reference internal" href="#_CPPv316metal_spi_config" title="metal_spi_config">metal_spi_config</a> *<em>config</em>, size_t <em>len</em>, char *<em>tx_buf</em>, char *<em>rx_buf</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv318metal_spi_transferP9metal_spiP16metal_spi_config6size_tPcPc" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Perform a SPI transfer. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 if the transfer succeeds </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">spi</span></code>: The handle for the SPI device to perform the transfer </li>
<li><code class="docutils literal notranslate"><span class="pre">config</span></code>: The configuration for the SPI transfer. </li>
<li><code class="docutils literal notranslate"><span class="pre">len</span></code>: The number of bytes to transfer </li>
<li><code class="docutils literal notranslate"><span class="pre">tx_buf</span></code>: The buffer to send over the SPI bus. Must be len bytes long. If NULL, the SPI will transfer the value 0. </li>
<li><code class="docutils literal notranslate"><span class="pre">rx_buf</span></code>: The buffer to receive data into. Must be len bytes long. If NULL, the SPI will ignore received bytes. </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv323metal_spi_get_baud_rateP9metal_spi">
<span id="_CPPv223metal_spi_get_baud_rateP9metal_spi"></span><span id="metal_spi_get_baud_rate__metal_spiP"></span><span class="target" id="spi_8h_1a2bce61c3c9ca996d880b24917c6f32d5"></span>int <code class="descname">metal_spi_get_baud_rate</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv39metal_spi" title="metal_spi">metal_spi</a> *<em>spi</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv323metal_spi_get_baud_rateP9metal_spi" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Get the current baud rate of the SPI device. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>The baud rate in Hz </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">spi</span></code>: The handle for the SPI device </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

<dl class="function">
<dt id="_CPPv323metal_spi_set_baud_rateP9metal_spii">
<span id="_CPPv223metal_spi_set_baud_rateP9metal_spii"></span><span id="metal_spi_set_baud_rate__metal_spiP.i"></span><span class="target" id="spi_8h_1af1e744929bc53d0a6ce6ba455d5732b6"></span>int <code class="descname">metal_spi_set_baud_rate</code><span class="sig-paren">(</span><em class="property">struct</em> <a class="reference internal" href="#_CPPv39metal_spi" title="metal_spi">metal_spi</a> *<em>spi</em>, int <em>baud_rate</em><span class="sig-paren">)</span><a class="headerlink" href="#_CPPv323metal_spi_set_baud_rateP9metal_spii" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>Set the current baud rate of the SPI device. </p>
<p><dl class="docutils">
<dt><strong>Return</strong></dt>
<dd>0 if the baud rate is successfully changed </dd>
<dt><strong>Parameters</strong></dt>
<dd><ul class="breatheparameterlist first last simple">
<li><code class="docutils literal notranslate"><span class="pre">spi</span></code>: The handle for the SPI device </li>
<li><code class="docutils literal notranslate"><span class="pre">baud_rate</span></code>: The desired baud rate of the SPI device </li>
</ul>
</dd>
</dl>
</p>
</dd></dl>

</div>
<dl class="class">
<dt id="_CPPv316metal_spi_config">
<span id="_CPPv216metal_spi_config"></span><span id="metal_spi_config"></span><span class="target" id="structmetal__spi__config"></span><em class="property">struct </em><code class="descname">metal_spi_config</code><a class="headerlink" href="#_CPPv316metal_spi_config" title="Permalink to this definition">¶</a><br /></dt>
<dd><em>#include &lt;spi.h&gt;</em><p>The configuration for a SPI transfer. </p>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Types</p>
<dl class="type">
<dt id="_CPPv312__anonymous0">
<span id="_CPPv212__anonymous0"></span><span id="__anonymous0"></span><span class="target" id="structmetal__spi__config_1a189893c917d826e5ded619ef8a45add3"></span><em class="property">enum </em><code class="descname"><strong>[anonymous]</strong></code><a class="headerlink" href="#_CPPv312__anonymous0" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The protocol for the SPI transfer. </p>
<p><em>Values:</em></p>
<dl class="enumerator">
<dt id="_CPPv316METAL_SPI_SINGLE">
<span id="_CPPv216METAL_SPI_SINGLE"></span><span class="target" id="structmetal__spi__config_1a189893c917d826e5ded619ef8a45add3a0c29eed4fe3e1f248d1810ba5dfe1a8e"></span><code class="descname">METAL_SPI_SINGLE</code><a class="headerlink" href="#_CPPv316METAL_SPI_SINGLE" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>

<dl class="enumerator">
<dt id="_CPPv314METAL_SPI_DUAL">
<span id="_CPPv214METAL_SPI_DUAL"></span><span class="target" id="structmetal__spi__config_1a189893c917d826e5ded619ef8a45add3a2d9fda1fb7661945d428297033fad17b"></span><code class="descname">METAL_SPI_DUAL</code><a class="headerlink" href="#_CPPv314METAL_SPI_DUAL" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>

<dl class="enumerator">
<dt id="_CPPv314METAL_SPI_QUAD">
<span id="_CPPv214METAL_SPI_QUAD"></span><span class="target" id="structmetal__spi__config_1a189893c917d826e5ded619ef8a45add3a426ecf339e41e2357824802c2b1e9746"></span><code class="descname">METAL_SPI_QUAD</code><a class="headerlink" href="#_CPPv314METAL_SPI_QUAD" title="Permalink to this definition">¶</a><br /></dt>
<dd></dd></dl>

</dd></dl>

</div>
<div class="breathe-sectiondef docutils container">
<p class="breathe-sectiondef-title rubric">Public Members</p>
<dl class="member">
<dt>
<span class="target" id="structmetal__spi__config_1a516959be864737cc77da242d8a30cd33"></span><code class="descname">metal_spi_config::&#64;0  metal_spi_config::protocol</code></dt>
<dd><p>The protocol for the SPI transfer. </p>
</dd></dl>

<dl class="member">
<dt id="_CPPv3N16metal_spi_config8polarityE">
<span id="_CPPv2N16metal_spi_config8polarityE"></span><span id="metal_spi_config::polarity__unsigned-i"></span><span class="target" id="structmetal__spi__config_1a4eacfe4cb2ce9f556bc93de3cb2a32da"></span>unsigned int <code class="descname">polarity</code><a class="headerlink" href="#_CPPv3N16metal_spi_config8polarityE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The polarity of the SPI transfer, equivalent to CPOL. </p>
</dd></dl>

<dl class="member">
<dt id="_CPPv3N16metal_spi_config5phaseE">
<span id="_CPPv2N16metal_spi_config5phaseE"></span><span id="metal_spi_config::phase__unsigned-i"></span><span class="target" id="structmetal__spi__config_1ae4d504bda2381f7c05cc754c72635233"></span>unsigned int <code class="descname">phase</code><a class="headerlink" href="#_CPPv3N16metal_spi_config5phaseE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The phase of the SPI transfer, equivalent to CPHA. </p>
</dd></dl>

<dl class="member">
<dt id="_CPPv3N16metal_spi_config13little_endianE">
<span id="_CPPv2N16metal_spi_config13little_endianE"></span><span id="metal_spi_config::little_endian__unsigned-i"></span><span class="target" id="structmetal__spi__config_1a75973254d44934f7f89e52033233f235"></span>unsigned int <code class="descname">little_endian</code><a class="headerlink" href="#_CPPv3N16metal_spi_config13little_endianE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The endianness of the SPI transfer. </p>
</dd></dl>

<dl class="member">
<dt id="_CPPv3N16metal_spi_config14cs_active_highE">
<span id="_CPPv2N16metal_spi_config14cs_active_highE"></span><span id="metal_spi_config::cs_active_high__unsigned-i"></span><span class="target" id="structmetal__spi__config_1adaecd64030bdbb756854bb213f2542fe"></span>unsigned int <code class="descname">cs_active_high</code><a class="headerlink" href="#_CPPv3N16metal_spi_config14cs_active_highE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The active state of the chip select line. </p>
</dd></dl>

<dl class="member">
<dt id="_CPPv3N16metal_spi_config4csidE">
<span id="_CPPv2N16metal_spi_config4csidE"></span><span id="metal_spi_config::csid__unsigned-i"></span><span class="target" id="structmetal__spi__config_1a894c54e76a7438715ab07b9459c23162"></span>unsigned int <code class="descname">csid</code><a class="headerlink" href="#_CPPv3N16metal_spi_config4csidE" title="Permalink to this definition">¶</a><br /></dt>
<dd><p>The chip select ID to activate for the SPI transfer. </p>
</dd></dl>

</div>
</dd></dl>

<dl class="class">
<dt id="_CPPv39metal_spi">
<span id="_CPPv29metal_spi"></span><span id="metal_spi"></span><span class="target" id="structmetal__spi"></span><em class="property">struct </em><code class="descname">metal_spi</code><a class="headerlink" href="#_CPPv39metal_spi" title="Permalink to this definition">¶</a><br /></dt>
<dd><em>#include &lt;spi.h&gt;</em><p>A handle for a SPI device. </p>
</dd></dl>

</div>


          </div>
          
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
<h1 class="logo"><a href="../index.html">Freedom Metal</a></h1>








<h3>Navigation</h3>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction to Freedom Metal</a></li>
<li class="toctree-l1"><a class="reference internal" href="../devguide.html">Developer Guide</a></li>
<li class="toctree-l1 current"><a class="reference internal" href="../api.html">API Reference</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="button.html">Buttons</a></li>
<li class="toctree-l2"><a class="reference internal" href="cache.html">Caches</a></li>
<li class="toctree-l2"><a class="reference internal" href="clock.html">Clocks</a></li>
<li class="toctree-l2"><a class="reference internal" href="cpu.html">CPU</a></li>
<li class="toctree-l2"><a class="reference internal" href="gpio.html">GPIO</a></li>
<li class="toctree-l2"><a class="reference internal" href="interrupt.html">Interrupts</a></li>
<li class="toctree-l2"><a class="reference internal" href="itim.html">ITIM</a></li>
<li class="toctree-l2"><a class="reference internal" href="led.html">LEDs</a></li>
<li class="toctree-l2"><a class="reference internal" href="lock.html">Locks</a></li>
<li class="toctree-l2"><a class="reference internal" href="memory.html">Memory Enumeration</a></li>
<li class="toctree-l2"><a class="reference internal" href="pmp.html">PMPs</a></li>
<li class="toctree-l2"><a class="reference internal" href="shutdown.html">Shutdown</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="#">SPIs</a></li>
<li class="toctree-l2"><a class="reference internal" href="switch.html">Switches</a></li>
<li class="toctree-l2"><a class="reference internal" href="timer.html">Timer API</a></li>
<li class="toctree-l2"><a class="reference internal" href="tty.html">TTY</a></li>
<li class="toctree-l2"><a class="reference internal" href="uart.html">UARTs</a></li>
</ul>
</li>
</ul>

<div class="relations">
<h3>Related Topics</h3>
<ul>
  <li><a href="../index.html">Documentation overview</a><ul>
  <li><a href="../api.html">API Reference</a><ul>
      <li>Previous: <a href="shutdown.html" title="previous chapter">Shutdown</a></li>
      <li>Next: <a href="switch.html" title="next chapter">Switches</a></li>
  </ul></li>
  </ul></li>
</ul>
</div>
<div id="searchbox" style="display: none" role="search">
  <h3>Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    </div>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="footer">
      &copy;2019, SiFive Inc..
      
      |
      Powered by <a href="http://sphinx-doc.org/">Sphinx 1.7.5</a>
      &amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.11</a>
      
      |
      <a href="../_sources/apiref/spi.rst.txt"
          rel="nofollow">Page source</a>
    </div>

    

    
  </body>
</html>